const http = require('http')
const fs = require('fs')

let server = http.createServer()

server.on('request', function (req, res) {
  if (req.url == '/') {
    fs.readFile('../data/index.html', function (err, data) {
      if (err) {
        res.setHeader('Content-Type', 'text/html; charset=utf-8')
        res.end('文件读取失败，请稍后重试！')
      } else {
        res.setHeader('Content-Type', 'text/html; charset=utf-8')
        res.end(data)
      }
    })
  }
})

server.listen('3000', function () {
  console.log('服务启动成功！');
})